
import org.apache.shiro.crypto.hash.Sha512Hash

import grails.util.GrailsUtil


import org.icress.fusion.shiro.*
import org.icress.fusion.admin.*
import org.icress.fusion.b2b.*
import org.icress.fusion.wf.*
import org.icress.fusion.ws.*

class aBootStrap {
    
    def grailsApplication

    def init = { servletContext ->
        switch(GrailsUtil.environment) {
            case "development":
                configureForDevelopment()
                break
            case "production":
                configureForDevelopment()
                break
        }
    }
    def configureForDevelopment = {
        /*init profile*/
        def adminProfile = new Profile(name:"Admin Profile").save(flush:true)
        def dealerProfile = new Profile(name:"Dealer Profile").save(flush:true)
        def deptProfile = new Profile(name:"Department Profile").save(flush:true)

        /*init page layout*/
        def recordType220 = new RecordType(serialNumber :'220', name:'客户订单', domain:'salesOrder', description:'', isActive:true).save(flush:true)
        def recordType221 = new RecordType(serialNumber :'221', name:'特价订单', domain:'salesOrder', description:'', isActive:true).save(flush:true)
        def recordType224 = new RecordType(serialNumber :'224', name:'项目订单', domain:'salesOrder', description:'', isActive:true).save(flush:true)
 
         
        new PageLayout(name:"dealer_220", domain : "salesOrder", recordType :recordType220, profile:adminProfile).save(flush:true)
        new PageLayout(name:"dealer_220", domain : "salesOrder", recordType :recordType220, profile:dealerProfile).save(flush:true)
        new PageLayout(name:"dealer_220", domain : "salesOrder", recordType :recordType220, profile:deptProfile).save(flush:true)
        
        new PageLayout(name:"dealer_221", domain : "salesOrder", recordType :recordType221, profile:adminProfile).save(flush:true)
        new PageLayout(name:"dealer_221", domain : "salesOrder", recordType :recordType221, profile:dealerProfile).save(flush:true)
        new PageLayout(name:"dealer_221", domain : "salesOrder", recordType :recordType221, profile:deptProfile).save(flush:true)

        new PageLayout(name:"dealer_224", domain : "salesOrder", recordType :recordType224, profile:adminProfile).save(flush:true)
        new PageLayout(name:"dealer_224", domain : "salesOrder", recordType :recordType224, profile:dealerProfile).save(flush:true)
        new PageLayout(name:"dealer_224", domain : "salesOrder", recordType :recordType224, profile:deptProfile).save(flush:true)

        
        //create user
        def adminUser = new User(username: "admin",  passwordHash: new Sha512Hash("admin").toHex(), profile:adminProfile).save(flush:true)
        //create role
        def roleAdmin = new Role(name:"Admin Role")
            .addToPermissions("*:*")
            .addToUsers(adminUser)
            .save(flush:true)

        /*init department, staff, owner, dealer*/
        //Commerce
            def dept1000 = new Department(serialNumber:'1000',name:'Commerce', type : 'C', parentDept : null, description:'L1',isActive:true).save(flush:true)
            def user1000_1 = new User(username: "Snyder Kathy".toLowerCase(),  passwordHash: new Sha512Hash("123456").toHex(), profile:deptProfile, department : dept1000).save(flush:true)
        //Western Region
            def dept3200 = new Department(serialNumber:'3200',name:'Western Region', type : 'R', parentDept : dept1000, description:'',isActive:true).save(flush:true)
            def user3200_1 = new User(username: "Monaco David".toLowerCase(),  passwordHash: new Sha512Hash("123456").toHex(), profile:deptProfile, department : dept3200).save(flush:true)
        //Branch-San Francisco
            def dept3210 = new Department(serialNumber:'3210',name:'San Francisco Branch', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
            def user3210_1 = new User(username: "Mcclure Brenda".toLowerCase(), passwordHash: new Sha512Hash("123456").toHex(), profile:deptProfile, department : dept3210).save(flush:true)
            def staff3200_1 = new Staff(serialNumber : '3200_1', name :'Bair Betty', department : dept3210).save(flush:true)
            def owner3210_1 = new User(username: "May Norm".toLowerCase(),  passwordHash: new Sha512Hash("123456").toHex(), profile:dealerProfile).save(flush:true)
            def dealer3210_1 = new Dealer(
                department:dept3210
                , serialNumber:'CC634267'
                , name:'Edge Communications'
                , alias:'Edge'
                , shortcut:null
                , salesMan:staff3200_1
                , head:'Forbes Sean'
                , contact:'Gonzalez Rose'
                , address1 : 'USA,66045 KS Lawrence, 1301 Hoch Drive'
                , address2 : ''
                , approvalStatus:'Y'
                , pricingMode:'Normal'
                , owner : owner3210_1
            ).save(flush:true)

/*
        def dept3220 = new Department(serialNumber:3220  ,name:'Los Angeles', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
        //CC947211
                def staff30000 = new Staff(serialNumber : '30000', name :'Song Arthur', department : dept3002).save(flush:true)
        def staff1000_1 = new Staff(serialNumber : '1000_1', name :'Pavlova Stella', department : dept1000).save(flush:true)
 
        def ownerCC947211 = new User(username: "CC947211".toLowerCase(),  passwordHash: new Sha512Hash("CC947211").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCC947211 = new Dealer(
            department:dept3220
            , serialNumber:'CC947211'
            , name:'Express Logistics and Transport'
            , alias:'Express'
            , shortcut:null
            , salesMan:staff40000
            , head:'Davis Josh'
            , contact:'Levy Babara'
            , address1 : 'OR Portland, 620 SW 5th Avenue Suite 400, Portland, Oregon 97204, United States'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal' 
            , owner : ownerCC947211 
        ).save(flush:true)
        
        def dept3230 = new Department(serialNumber:3230  ,name:'Las Vegas', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
        //CC213425
        def ownerCC213425 = new User(username: "CC213425".toLowerCase(),  passwordHash: new Sha512Hash("CC213425").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCC213425 = new Dealer(
            department:dept3230
            , serialNumber:'CC213425'
            , name:'Pyramid Construction Inc.'
            , alias:'Pyramid'
            , shortcut:'PYR'
            , salesMan:staff20000
            , head:'Stumuller Pat'
            , contact:'Cotton Phyllis'
            , address1 : 'USA, 27215 NC Burlington, 525 S. Lexington Ave'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCC213425
        ).save(flush:true)
        
        def dept3240 = new Department(serialNumber:3240  ,name:'Lake City', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
        //CC978213
        def ownerCC978213 = new User(username: "CC978213".toLowerCase(),  passwordHash: new Sha512Hash("CC978213").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCC978213 = new Dealer(
            department:dept3240
            , serialNumber:'CC978213'
            , name:'GenePoint'
            , alias:'GenePoint'
            , shortcut:''
            , salesMan:staff20000
            , head:"Grey Jane"
            , contact:'James Tom'
            , address1 : 'CA Mountain View, 345 Shoreline Park, Mountain View, CA 94043, USA'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCC978213
        ).save(flush:true)
        
        def dept3250 = new Department(serialNumber:3250  ,name:'Seattle', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
        //CD439877
        def ownerCD439877 = new User(username: "CD439877".toLowerCase(),  passwordHash: new Sha512Hash("CD439877").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD439877 = new Dealer(
            department:dept3250
            , serialNumber:'CD439877'
            , name:'Grand Hotels & Resorts Ltd'
            , alias:'Grand'
            , shortcut:null
            , salesMan:staff40000
            , head:'Barr Tim'
            , contact:'Bond John'
            , address1 : 'IL Chicago, 2334 N. Michigan Avenue, Suite 1500, Chicago, IL 60601, USA'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal' 
            , owner : ownerCD439877 
        ).save(flush:true)
        
        def dept3260 = new Department(serialNumber:3260  ,name:'Denver', type : 'B', parentDept : dept3200, description:'',isActive:true).save(flush:true)
        //CD451796
        def ownerCD451796 = new User(username: "CD451796".toLowerCase(),  passwordHash: new Sha512Hash("CD451796").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD451796 = new Dealer(
            department:dept3310
            , serialNumber:'CD451796'
            , name:'Dickenson plc'
            , alias:'Dickenson'
            , shortcut:null
            , salesMan:staff40000
            , head:'Young Andy'
            , contact:'Young Andy'
            , address1 : 'TX Austin, 312 Constitution Place, Austin, TX 78767, USA'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal' 
            , owner : ownerCD451796 
        ).save(flush:true)

        //eastern 
        def dept3300 = new Department(serialNumber:3300  ,name:'Eastern Region', type : 'R', parentDept : dept1000, description:'',isActive:true).save(flush:true)
        def dept3310 = new Department(serialNumber:3310  ,name:'New York', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)
        //CD656092
        def ownerCD656092 = new User(username: "CD656092".toLowerCase(),  passwordHash: new Sha512Hash("CD656092").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD656092 = new Dealer(
            department:dept3310
            , serialNumber:'CD656092'
            , name:'Burlington Textiles Corp of America'
            , alias:'Burlington'
            , shortcut:'BTXT'
            , salesMan:staff20000
            , head:'Rogers Jack'
            , contact:'Rogers Jack'
            , address1 : 'USA, 27215 NC Burlington, 525 S. Lexington Ave'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCD656092
        ).save(flush:true)
        
        def dept3320 = new Department(serialNumber:3320  ,name:'Atlanta', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)
        def owner = new User(username: "CD656092".toLowerCase(),  passwordHash: new Sha512Hash("CD656092").toHex(), profile:dealerProfile).save(flush:true)
        def dealer = new Dealer(
            department:dept3210
            , serialNumber:'CD656092'
            , name:'sForce'
            , alias:'sForce'
            , shortcut:''
            , salesMan:staff20000
            , head:'Llorrac Jake'
            , contact:'Nedaerk Siddartha'
            , address1 : 'US, 94087 CA San Francisco, The Landmark @ One Market'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : owner
        ).save(flush:true)
        
        def dept3330 = new Department(serialNumber:3330  ,name:'ST Lous', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)
        //CD355118
        def ownerCD355118 = new User(username: "CD355118".toLowerCase(),  passwordHash: new Sha512Hash("CD355118").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD355118 = new Dealer(
            department:dept3330
            , serialNumber:'CD355118'
            , name:'United Oil & Gas Corp.'
            , alias:'Oil & Gas'
            , shortcut:''
            , salesMan:staff20000
            , head:'Boyle Lauren'
            , contact:'Green Avi'
            , address1 : 'NY New York, 1301 Avenue of the Americas , New York, NY 10019, USA'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCD355118
        ).save(flush:true)

        def dept3340 = new Department(serialNumber:3340  ,name:'Houston', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)


        def dept3350 = new Department(serialNumber:3350  ,name:'Austin', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)
        //CD736025
        def ownerCD355119_A = new User(username: "CD736025".toLowerCase(),  passwordHash: new Sha512Hash("CD736025").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD355119_A = new Dealer(
            department:dept3210
            , serialNumber:'CD736025'
            , name:'University of Arizona'
            , alias:'Arizona'
            , shortcut:''
            , salesMan:staff20000
            , head:"Grey Jane"
            , contact:'Grey Jane'
            , address1 : 'AZ Tucson, 888 N Euclid , Hallis Center, Room 501, Tucson, AZ 85721, United States'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCD355119_A
        ).save(flush:true)
        
        def dept3360 = new Department(serialNumber:3360  ,name:'Chicago', type : 'B', parentDept : dept3300, description:'',isActive:true).save(flush:true)
        
        def dept3400 = new Department(serialNumber:3400  ,name:'International', type : 'R', parentDept : dept1000, description:'',isActive:true).save(flush:true)
        def dept3410 = new Department(serialNumber:3410  ,name:'Vancouver', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
        def dept3420 = new Department(serialNumber:3420  ,name:'London', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
        //CD355119-A
        def ownerCD355119_A = new User(username: "CD355119-A".toLowerCase(),  passwordHash: new Sha512Hash("CD355119-A").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD355119_A = new Dealer(
            department:dept3210
            , serialNumber:'CD355118'
            , name:'United Oil & Gas, UK'
            , alias:'Oil & Gas'
            , shortcut:''
            , salesMan:staff20000
            , head:"James Ashley"
            , contact:'James Ashley'
            , address1 : 'UK, Kings Park, 17th Avenue, Team Valley Trading Estate, Gateshead, Tyne and Wear NE26 3HS, United Kingdom'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCD355119_A
        ).save(flush:true)


        def dept3430 = new Department(serialNumber:3430  ,name:'Tokyo', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
        //CD355120-B
        def ownerCD355118_B = new User(username: "CD355120-B".toLowerCase(),  passwordHash: new Sha512Hash("CD355120-B").toHex(), profile:dealerProfile).save(flush:true)
        def dealerCD355118_B = new Dealer(
            department:dept3430
            , serialNumber:'CD355118'
            , name:'United Oil & Gas Corp.'
            , alias:'Oil & Gas'
            , shortcut:''
            , salesMan:staff20000
            , head:"D'Cruz Liz"
            , contact:'Ripley Tom'
            , address1 : 'Singapore Singapore, 9 Tagore Lane, Singapore, Singapore 787472, Singapore'
            , address2 : ''
            , approvalStatus:'Y'
            , pricingMode:'Normal'
            , owner : ownerCD355118_B
        ).save(flush:true)

        def dept3440 = new Department(serialNumber:3440  ,name:'Berlin', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
        def dept3450 = new Department(serialNumber:3450  ,name:'Paris', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
        def dept3460 = new Department(serialNumber:3460  ,name:'Canberra', type : 'B', parentDept : dept3400, description:'',isActive:true).save(flush:true)
*/
        
        def roleDepartment = new Role(name:"Department Role[Approval]")
	        .addToPermissions("index:*")
	        .addToPermissions("nav:*")
	        .addToPermissions("auth:*")
            .addToPermissions("welcome:*")

	        .addToPermissions("contract:index")
	        .addToPermissions("contract:list")
	        .addToPermissions("contract:show")

	        .addToPermissions("salesOrder:index")
	        .addToPermissions("salesOrder:list")
	        .addToPermissions("salesOrder:show")
	        .addToPermissions("workflowApproval:confirm")
	        .addToPermissions("workflowApproval:approval")
	        .addToPermissions("salesOrderAjax:workflowHistory")
            .addToPermissions("salesOrderAjax:outBoundMessage")

            .addToPermissions("report:run")
            .addToPermissions("report:view")

            .addToPermissions("outBound:index")
            .addToPermissions("outBound:list")
            .addToPermissions("outBound:show")
            .addToPermissions("outBound:resurrect")
            .addToPermissions("outBound:showXml")

            .addToPermissions("creditControl:index")
            .addToPermissions("creditControl:list")
            .addToPermissions("creditControl:show")
            
	        .addToUsers(user1000_1)
	        .addToUsers(user3210_1)
	        .save(flush:true)

        def roleDepartmentReadonly = new Role(name:"Department Role[Readonly]")
	        .addToPermissions("index:*")
	        .addToPermissions("nav:*")
	        .addToPermissions("auth:*")
            .addToPermissions("welcome:*")

	        .addToPermissions("contract:index")
	        .addToPermissions("contract:list")
	        .addToPermissions("contract:show")

	        .addToPermissions("salesOrder:index")
	        .addToPermissions("salesOrder:list")
	        .addToPermissions("salesOrder:show")
	        .addToPermissions("salesOrderAjax:workflowHistory")
            .addToPermissions("salesOrderAjax:outBoundMessage")

            .addToPermissions("report:run")
            .addToPermissions("report:view")

            .addToPermissions("outBound:index")
            .addToPermissions("outBound:list")
            .addToPermissions("outBound:show")
            .addToPermissions("outBound:showXml")

            .addToPermissions("creditControl:index")
            .addToPermissions("creditControl:list")
            .addToPermissions("creditControl:show")

	        .addToUsers(user3200_1)
	        .save(flush:true)

        def roleDealer = new Role(name:"Dealer Role")
        .addToPermissions("index:*")
        .addToPermissions("nav:*")
        .addToPermissions("auth:*")
        .addToPermissions("welcome:*")

        .addToPermissions("contract:index")
        .addToPermissions("contract:list")
        .addToPermissions("contract:show")

        .addToPermissions("salesOrder:index")
        .addToPermissions("salesOrder:list")
        .addToPermissions("salesOrder:create")
        .addToPermissions("salesOrder:save")
        .addToPermissions("salesOrder:show")
        .addToPermissions("salesOrder:edit")
        .addToPermissions("salesOrder:update")

		.addToPermissions("salesOrderAjax:*")

        .addToPermissions("workflowApproval:confirm")
        .addToPermissions("workflowApproval:approval")

        .addToPermissions("report:run")
        .addToPermissions("report:view")

        .addToPermissions("creditControl:index")
        .addToPermissions("creditControl:list")
        .addToPermissions("creditControl:show")

        .addToUsers(owner3210_1)
        .save(flush:true)

      /*init industry*/
def industryAgriculture = new Industry(serialNumber:'000001', shortName:'Agriculture', fullName:'Agriculture', isActive:true, description:'').save(flush:true)
def industryApparel = new Industry(serialNumber:'000002', shortName:'Apparel', fullName:'Apparel', isActive:true, description:'').save(flush:true)
def industryBanking = new Industry(serialNumber:'000003', shortName:'Banking', fullName:'Banking', isActive:true, description:'').save(flush:true)
def industryBiotechnology = new Industry(serialNumber:'000004', shortName:'Biotechnology', fullName:'Biotechnology', isActive:true, description:'').save(flush:true)
def industryChemicals = new Industry(serialNumber:'000005', shortName:'Chemicals', fullName:'Chemicals', isActive:true, description:'').save(flush:true)
def industryCommunications = new Industry(serialNumber:'000006', shortName:'Communications', fullName:'Communications', isActive:true, description:'').save(flush:true)
def industryConstruction = new Industry(serialNumber:'000007', shortName:'Construction', fullName:'Construction', isActive:true, description:'').save(flush:true)
def industryConsulting = new Industry(serialNumber:'000008', shortName:'Consulting', fullName:'Consulting', isActive:true, description:'').save(flush:true)
def industryEducation = new Industry(serialNumber:'000009', shortName:'Education', fullName:'Education', isActive:true, description:'').save(flush:true)
def industryElectronics = new Industry(serialNumber:'000010', shortName:'Electronics', fullName:'Electronics', isActive:true, description:'').save(flush:true)
def industryEnergy = new Industry(serialNumber:'000011', shortName:'Energy', fullName:'Energy', isActive:true, description:'').save(flush:true)
def industryEngineering = new Industry(serialNumber:'000012', shortName:'Engineering', fullName:'Engineering', isActive:true, description:'').save(flush:true)
def industryEntertainment = new Industry(serialNumber:'000013', shortName:'Entertainment', fullName:'Entertainment', isActive:true, description:'').save(flush:true)
def industryEnvironmental = new Industry(serialNumber:'000014', shortName:'Environmental', fullName:'Environmental', isActive:true, description:'').save(flush:true)
def industryFinance = new Industry(serialNumber:'000015', shortName:'Finance', fullName:'Finance', isActive:true, description:'').save(flush:true)
def industryFoodAndBeverage = new Industry(serialNumber:'000016', shortName:'Food & Beverage', fullName:'Food & Beverage', isActive:true, description:'').save(flush:true)
def industryGovernment = new Industry(serialNumber:'000017', shortName:'Government', fullName:'Government', isActive:true, description:'').save(flush:true)
def industryHealthcare = new Industry(serialNumber:'000018', shortName:'Healthcare', fullName:'Healthcare', isActive:true, description:'').save(flush:true)
def industryHospitality = new Industry(serialNumber:'000019', shortName:'Hospitality', fullName:'Hospitality', isActive:true, description:'').save(flush:true)
def industryInsurance = new Industry(serialNumber:'000020', shortName:'Insurance', fullName:'Insurance', isActive:true, description:'').save(flush:true)
def industryMachinery = new Industry(serialNumber:'000021', shortName:'Machinery', fullName:'Machinery', isActive:true, description:'').save(flush:true)
def industryManufacturing = new Industry(serialNumber:'000022', shortName:'Manufacturing', fullName:'Manufacturing', isActive:true, description:'').save(flush:true)
def industryMedia = new Industry(serialNumber:'000023', shortName:'Media', fullName:'Media', isActive:true, description:'').save(flush:true)
def industryNotForProfit = new Industry(serialNumber:'000024', shortName:'Not For Profit', fullName:'Not For Profit', isActive:true, description:'').save(flush:true)
def industryRecreation = new Industry(serialNumber:'000025', shortName:'Recreation', fullName:'Recreation', isActive:true, description:'').save(flush:true)
def industryRetail = new Industry(serialNumber:'000026', shortName:'Retail', fullName:'Retail', isActive:true, description:'').save(flush:true)
def industryShipping = new Industry(serialNumber:'000027', shortName:'Shipping', fullName:'Shipping', isActive:true, description:'').save(flush:true)
def industryTechnology = new Industry(serialNumber:'000028', shortName:'Technology', fullName:'Technology', isActive:true, description:'').save(flush:true)
def industryTelecommunications = new Industry(serialNumber:'000029', shortName:'Telecommunications', fullName:'Telecommunications', isActive:true, description:'').save(flush:true)
def industryTransportation = new Industry(serialNumber:'000030', shortName:'Transportation', fullName:'Transportation', isActive:true, description:'').save(flush:true)
def industryUtilities = new Industry(serialNumber:'000031', shortName:'Utilities', fullName:'Utilities', isActive:true, description:'').save(flush:true)
def industryOther = new Industry(serialNumber:'000032', shortName:'Other', fullName:'Other', isActive:true, description:'').save(flush:true)
        /*Category*/
        def recordType11 = new RecordType (serialNumber : '1', name : 'Accountant', domain : 'category',  isActive : true, description : '').save(flush:true)
            def category11_001 = new Category (recordType : recordType11, serialNumber : '001', name : 'Accessory', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category11_002 = new Category (recordType : recordType11, serialNumber : '002', name : 'Material', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category11_003 = new Category (recordType : recordType11, serialNumber : '003', name : 'Finished Product', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category11_004 = new Category (recordType : recordType11, serialNumber : '004', name : 'Purchased Finished Products', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)

        def recordType12 = new RecordType (serialNumber : '2', name : 'Warehouse', domain : 'category',  isActive : true, description : '').save(flush:true)
        
            def category12_001 = new Category (recordType : recordType12, serialNumber : '001', name : 'F1-1', discount : 0, productionCycle:2, transportCycle:5, isActive:true).save(flush:true)
            def category12_002 = new Category (recordType : recordType12, serialNumber : '002', name : 'F1-2', discount : 0,productionCycle:2, transportCycle:6, isActive:true).save(flush:true)
            def category12_003 = new Category (recordType : recordType12, serialNumber : '003', name : 'F2-1', discount : 0,productionCycle:2, transportCycle:7, isActive:true).save(flush:true)
            def category12_004 = new Category (recordType : recordType12, serialNumber : '004', name : 'F2-2', discount : 0, productionCycle:2, transportCycle:8, isActive:true).save(flush:true)
            def category12_005 = new Category (recordType : recordType12, serialNumber : '005', name : 'F3', discount : 0, productionCycle:2, transportCycle:9, isActive:true).save(flush:true)
        
        def recordType13 = new RecordType (serialNumber : '3', name : 'Product', domain : 'category',  isActive : true, description : '').save(flush:true)
            def category13_A01 = new Category (recordType : recordType13, serialNumber : 'A01', name : 'Diesel', discount : 0,productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category13_A02 = new Category (recordType : recordType13, serialNumber : 'A02', name : 'Gasoline', discount : 0,productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category13_A03 = new Category (recordType : recordType13, serialNumber : 'A03', name : 'Propane', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category13_A04 = new Category (recordType : recordType13, serialNumber : 'A04', name : 'Industrial', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category13_A05 = new Category (recordType : recordType13, serialNumber : 'A05', name : 'SLA', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            
        def recordType14 = new RecordType (serialNumber : '4', name : 'Client', domain : 'category',  isActive : true, description : '').save(flush:true)
            def category14_B11 = new Category (recordType : recordType14, serialNumber : 'B11', name : 'Factory', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category14_B12 = new Category (recordType : recordType14, serialNumber : 'B12', name : 'OEM', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)
            def category14_B13 = new Category (recordType : recordType14, serialNumber : 'B13', name : 'Panasonic', discount : 0, productionCycle:0, transportCycle:0, isActive:true).save(flush:true)                

        def recordType15 = new RecordType (serialNumber : '5', name : 'Property', domain : 'category',  isActive : true, description : '').save(flush:true)        
            def category15_001 = new Category (recordType : recordType15, serialNumber : '001', name : 'Master Device(Diesel)', discount : 0.62, productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)
            def category15_002 = new Category (recordType : recordType15, serialNumber : '002', name : 'Master Device(Gasoline)', discount : 0.65,productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)
            def category15_003 = new Category (recordType : recordType15, serialNumber : '003', name : 'Master Device(Propane)', discount : 0.625,productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)
            def category15_004 = new Category (recordType : recordType15, serialNumber : '004', name : 'Master Device(Industrial)', discount : 0.7,productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)
            def category15_005 = new Category (recordType : recordType15, serialNumber : '005', name : 'Master Device(SLA)', discount : 0.675,productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)
            def category15_006 = new Category (recordType : recordType15, serialNumber : '006', name : 'Accessory', discount : 1,productionCycle:0, transportCycle:0, isActive:true, isAllowSpecialDiscount:true, isAllowZeroPrice : true).save(flush:true)


        //GC1020
        def productGC1020 = new Product(
            serialNumber:'GC1020'
            , name:'GenWatt Diesel 10kW'
            , standard:'GenWatt Diesel 10kW'
            , unit : 'suit'
            , price : 5000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_001))
            .addToCategories(new ProductCategory(category : category13_A01))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_001))
            .save(flush:true)
        //GC1040
        def productGC1040 = new Product(
            serialNumber:'GC1040'
            , name:'GenWatt Diesel 200kW'
            , standard:'GenWatt Diesel 200kW'
            , unit : 'suit'
            , price : 25000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_002))
            .addToCategories(new ProductCategory(category : category13_A01))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_001))
            .save(flush:true)            
        //GC1060
        def productGC1060 = new Product(
            serialNumber:'GC1060'
            , name:'GenWatt Diesel 1000kW'
            , standard:'GenWatt Diesel 1000kW'
            , unit : 'suit'
            , price : 100000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_003))
            .addToCategories(new ProductCategory(category : category13_A01))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_001))
            .save(flush:true)

        //GC3020
        def productGC3020 = new Product(
            serialNumber:'GC3020'
            , name:'GenWatt Propane 100kW'
            , standard:'GenWatt Propane 100kW'
            , unit : 'suit'
            , price : 15000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_004))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_003))
            .save(flush:true)
        //GC3040
        def productGC3040 = new Product(
            serialNumber:'GC3040'
            , name:'GenWatt Propane 500kW'
            , standard:'GenWatt Propane 500kW'
            , unit : 'suit'
            , price : 50000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_005))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_003))
            .save(flush:true)
        //GC3060
        def productGC3060 = new Product(
            serialNumber:'GC3060'
            , name:'GenWatt Propane 1500kW'
            , standard:'GenWatt Propane 1500kW'
            , unit : 'suit'
            , price : 120000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_001))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_003))
            .save(flush:true)

        //GC5020
        def productGC5020 = new Product(
            serialNumber:'GC5020'
            , name:'GenWatt Gasoline 300kW'
            , standard:'GenWatt Gasoline 300kW'
            , unit : 'suit'
            , price : 35000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_002))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //GC5040
        def productGC5040 = new Product(
            serialNumber:'GC5040'
            , name:'GenWatt Gasoline 750kW'
            , standard:'GenWatt Gasoline 750kW'
            , unit : 'suit'
            , price : 75000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_003))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //GC5060
        def productGC5060 = new Product(
            serialNumber:'GC5060'
            , name:'GenWatt Gasoline 2000kW'
            , standard:'GenWatt Gasoline 2000kW'
            , unit : 'suit'
            , price : 150000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_004))
            .addToCategories(new ProductCategory(category : category13_A03))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //IN7020
        def productIN7020 = new Product(
            serialNumber:'IN7020'
            , name:'Installation: Portable'
            , standard:'Installation: Portable'
            , unit : 'suit'
            , price : 5000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_005))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //IN7040
        def productIN7040 = new Product(
            serialNumber:'IN7040'
            , name:'Installation: Industrial - Low'
            , standard:'Installation: Industrial - Low'
            , unit : 'suit'
            , price : 20000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_001))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //IN7060
        def productIN7060 = new Product(
            serialNumber:'IN7060'
            , name:'Installation: Industrial - Medium'
            , standard:'Installation: Industrial - Medium'
            , unit : 'suit'
            , price : 50000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_002))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)
        //IN7080
        def productIN7080 = new Product(
            serialNumber:'IN7080'
            , name:'Installation: Industrial - High'
            , standard:'Installation: Industrial - High'
            , unit : 'suit'
            , price : 50000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_003))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_002))
            .save(flush:true)

        //SL9020
        def productSL9020 = new Product(
            serialNumber:'SL9020'
            , name:'SLA: Bronze'
            , standard:'SLA: Bronze'
            , unit : 'suit'
            , price : 10000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_004))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_005))
            .save(flush:true)

        //SL9040
        def productSL9040 = new Product(
            serialNumber:'SL9040'
            , name:'SLA: Silver'
            , standard:'SLA: Silver'
            , unit : 'suit'
            , price : 20000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_005))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_005))
            .save(flush:true)

        //SL9060
        def productSL9060 = new Product(
            serialNumber:'SL9060'
            , name:'SLA: Gold'
            , standard:'SLA: Gold'
            , unit : 'suit'
            , price : 30000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_001))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_005))
            .save(flush:true)

        //SL9080
        def productSL9080 = new Product(
            serialNumber:'SL9080'
            , name:'SLA: Platinum'
            , standard:'SLA: Platinum'
            , unit : 'suit'
            , price : 40000.00
            , isIncludeTax: true
            , isActive:true
        ).addToCategories(new ProductCategory(category : category11_003))
            .addToCategories(new ProductCategory(category : category12_002))
            .addToCategories(new ProductCategory(category : category13_A04))
            .addToCategories(new ProductCategory(category : category14_B11))
            .addToCategories(new ProductCategory(category : category15_005))
            .save(flush:true)

        /*init contract*/
        def recordType21 = new RecordType (serialNumber : '1', name : '行业特价申请', domain : 'contract',  isActive : true, description : '').save(flush:true)
            def contractYX24Z201108030005 = new Contract(
                serialNumber:'YX24Z201108030005'
                , recordType:recordType21
                , subject : 'Burlington Textiles Weaving Plant Generator'
                , applicant:'John Deere'
                , filingDate : new Date()
                , effectiveDate:new Date() + 1
                , dealer : dealer3210_1
                , project : 'Burlington Textiles Weaving Plant Generator'
                , industry : industryAgriculture
                , description : ''
                , createdBy : adminUser
                , lastModifiedBy:adminUser
                , owner:owner3210_1
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'1', category : category12_005, discount : 0.62, specialDiscount: 0.32, finalDiscount:0.42, expiryDate : new Date() + 180)
                ).save(flush:true)
            def contractYX09G201108190043 = new Contract(
                serialNumber:'YX09G201108190043'
                , recordType:recordType21
                , subject : 'Burlington Textiles Weaving Plant Generator'
                , applicant:'May Norm'
                , filingDate : new Date()
                , effectiveDate:new Date() + 1
                , dealer : dealer3210_1
                , project : 'Burlington Textiles Weaving Plant Generator'
                , industry : industryAgriculture
                , description : ''
                , createdBy : adminUser
                , lastModifiedBy:adminUser
                , owner:owner3210_1
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'1', category : category12_001, discount : 0.60, specialDiscount: 0.2, finalDiscount:0.48, expiryDate : new Date() + 180)
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'2', category : category12_002, discount : 0.60, specialDiscount: 0.01, finalDiscount:0.594, expiryDate : new Date() + 180)
                ).save(flush:true)
            
        /*221 非行业特价申请单*/
        def recordType22 = new RecordType (serialNumber : '2', name : '非行业特价申请', domain : 'contract',  isActive : true, description : '').save(flush:true)
            def contractYX09G201108190041 = new Contract(
                serialNumber:'YX09G201108190041'
                , recordType:recordType22
                , subject : 'Grand Hotels Emergency Generators'
                , applicant:'Caterpillar'
                , filingDate : new Date()
                , effectiveDate:new Date() + 1
                , dealer : dealer3210_1
                , project : 'Grand Hotels Emergency Generators'
                , industry : industryEnergy
                , description : ''
                , createdBy : adminUser
                , lastModifiedBy:adminUser
                , owner:owner3210_1
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'1', category : category12_003, discount : 0.625, specialDiscount: 0.08, finalDiscount:0.575, expiryDate : new Date() + 180)
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'2', category : category12_004, discount : 0.625, specialDiscount: 0.10, finalDiscount:0.5625, expiryDate : new Date() +180)
                ).save(flush:true)

            def contractYX09G201108190042 = new Contract(
                serialNumber:'YX09G201108190042'
                , recordType:recordType22
                , subject : 'Grand Hotels Emergency Generators'
                , applicant:'Caterpillar'
                , filingDate : new Date()
                , effectiveDate:new Date() + 1
                , dealer : dealer3210_1
                , project : 'Grand Hotels Emergency Generators'
                , industry : industryEnergy
                , description : ''
                , createdBy :adminUser 
                , lastModifiedBy:adminUser
                , owner:owner3210_1
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'1', category : category12_003, discount : 0.625, specialDiscount: 0.10, finalDiscount:0.5625, expiryDate : new Date() +180)
                ).addToContractDetails(
                    new ContractDetail(serialNumber:'2', category : category12_004, discount : 0.625, specialDiscount: 0.08, finalDiscount:0.575, expiryDate : new Date() + 180)
                ).save(flush:true)
    }

    def destroy = {
    }
}
